package com.ecut.xzh.mapper;

import com.ecut.xzh.vo.VoucherVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.ArrayList;

/**
 * @author XZH
 */
@Mapper
public interface VoucherMapper {
    /**
     * 获取优惠券信息
     * @return
     */
    @Select("select * from voucher")
    ArrayList<VoucherVO> select();

    /**
     * 根据id查询优惠券信息
     * @param id
     * @return
     */
    @Select("select * from voucher where id = #{id}")
    VoucherVO getById(Long id);

    /**
     * 获取优惠券库存数量
     * @return
     */
    @Select("select count(*) from voucher")
    int count();

    /**
     * 扣减优惠券
     * @param id
     * @return
     */
    @Update("update voucher set stock = stock - 1 where id = #{id}")
    Boolean minusStore(Long id);
}
